package cn.t222.controller.sys;

import cn.t222.pojo.Result;
import cn.t222.pojo.SysResources;
import cn.t222.service.ResourceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sys")
public class ResourceController {
    @Autowired private ResourceService resourceService;

    @PostMapping("/resource/add")
    public Result add(SysResources resources) {
        resourceService.add(resources);
        return Result.ok("200","success", null);
    }
    @GetMapping("/resource/del")
    public Result del(Integer id) {
        resourceService.del(id);
        return Result.ok("200","success", null);
    }
    @PostMapping("/resource/update")
    public Result update(SysResources resources) {
        resourceService.update(resources);
        return Result.ok("200","success", null);
    }
    @GetMapping("/resource/get")
    public Result get(Integer id) {
        return Result.ok("200","success", resourceService.get(id));
    }
    @GetMapping("/resource/list")
    public Result getAll(@RequestParam(defaultValue = "1") Integer page,
                         @RequestParam(defaultValue = "10") Integer limit) {
        PageHelper.startPage(page, limit);
        List<SysResources> list = resourceService.getAll();
        PageInfo<SysResources> pageInfo = PageInfo.of(list);
        return Result.ok("200","success", pageInfo);
    }
}
